#include "widget.h"
#include "ui_widget.h"

#include "QtMqtt/qmqttclient.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
    , mqttClient(new MqttClient(this, ui))  // 初始化 MqttClient 成员变量，并传递 ui 指针
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_conButton_clicked()
{
    qDebug() << "连接服务器" <<endl;
    ui->rec_plainText->setPlainText("这是我要添加的文本。");

    mqttClient->connectSever();

}

void Widget::on_subButton_clicked()
{
    mqttClient->subTopic();
}

void Widget::on_pubButton_clicked()
{
    QByteArray message = "Hello, MQTT!"; // 要发布的消息内容
        QString topic = "VS_LoRa/data"; // 替换为你想要发布的主题

        mqttClient->pubTopic(message, topic, 0); // 发布消息到指定主题，QoS 设置为 1
}
